﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using System.Reflection ;
using log4net;
using System.Text.RegularExpressions;

namespace AnyOffice.general.ipanel
{
    public partial class smsbox : BasePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
       
        public string formatContent(string strContent)
        {
            strContent = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase).Replace(strContent, "<a href=$1 target=_blank>$1</a>");
            strContent = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase).Replace(strContent, "<a href=mailto:$1>$1</a>");
            return strContent.Replace("\n", "<br>");
        }
        private void GetSms()
        {
            DataTable table = new SmsDao().SmsBoxSelect(base.Conn, base.User.Identity.Name);
            if (table.Rows.Count > 0)
            {
                this.pnlMain.Visible = true;
                this.rptSms.DataSource = table;
                this.rptSms.DataBind();
            }
            else
            {
                this.pnlMain.Visible = false;
                this.litMessage.Text = base.ShowMessage("无短信息").Replace("180", "160");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    this.GetSms();
                }
                if (this.Page.IsPostBack)
                {
                    new SmsDao().SmsBoxDelete(base.Conn, base.User.Identity.Name);
                    this.GetSms();
                }
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        }
 
    }
}
